package pkg.v2.parser


import _root_.v2.parser._
import load.{Unpickler, Pickler}

/**
 * @author bweber
 * @version $Rev$, $Date$
 */

object PicklerMain extends Application {
  
  val strType = Type("str")
  val fooType = Type("foo",Attr("first name",Type.typeRef("str")),Attr("last name",Type.typeRef("str")))
  val single = Single(Type.typeRef("foo"))
  val bunch = Bunch(Type.typeRef("foo"))
  val values:List[Value] =  Type.listTypes :: single :: bunch :: List[Value]()
  
  val result8 = Pickler(values)
  println(result8)
  
  println("**********************************************************************************")
  println("**********************************************************************************")
  println("**********************************************************************************")
  println("**********************************************************************************")
  println("**********************************************************************************")
  
  val unparser = new Unpickler()
  val nameStr = "\"hiya\""
  val attrdefStr = ""
  val attrdefsStr = ""
  def getTypeDefStr(name:String) = {
    "{ \"Type\" : { \"type\" : \"" + name + "\" \n } }"
  }
  def getTypeDef2Str(name:String) = {
    "{ \"Type\" : { \"type\" : \"" + name + "\", \"attrs\" : { \"g\" : \"h\", \"i\" : \"j\" } } }"
  }
  val typeRefStr = "\"cheese\""
  val attrRefStr = "\"bleh\""
  val slotStr = ""
  val slotsStr = ""
  val singleStr = "{ \"single\" : { \"type\" : \"mytype\" } }"
  val single2Str = "{ \"single\" : { \"type\" : \"mytype2\", \"slots\" : { \"o\" : \"p\", \"q\" : \"r\" } } }"
  val bunchStr = "{ \"bunch\" : { \"type\" : \"mytype3\" } }"
  val bunch2Str = "{ \"bunch\" : { \"type\" : \"mytype4\", \"slots\" : { \"s\" : \"t\", \"u\" : \"v\" } } }"
  println(unparser.parse(unparser.name,nameStr))
  println(unparser.parse(unparser.attrdef,"\"foo\" : \"bar\""))
  println(unparser.parse(unparser.attrdefs,", \"attrs\" : { \"a\" : \"b\", \"c\" : \"d\" }"))
  println(unparser.parse(unparser.typedef,getTypeDefStr("val2")))
  println(unparser.parse(unparser.typedef,getTypeDef2Str("val3")))
  println(unparser.parse(unparser.attrref,attrRefStr))
  println(unparser.parse(unparser.typeref,typeRefStr))
  println(unparser.parse(unparser.slot,"\"k\" : \"l\""))
  println(unparser.parse(unparser.slots,", \"slots\" : { \"m\" : \"n\" }"))
//  println(unparser.parse(unparser.slots,", \"slots\" : { \"m\" : \"n\", \"o\" : \"p\" }"))
  println(unparser.parse(unparser.single,singleStr))
  println(unparser.parse(unparser.single,single2Str))
  println(unparser.parse(unparser.bunch,bunchStr))
  println(unparser.parse(unparser.bunch,bunch2Str))
  println(unparser.parse(unparser.value,singleStr))
  println(unparser.parse(unparser.value,single2Str))
  println(unparser.parse(unparser.value,bunchStr))
  println(unparser.parse(unparser.value,bunch2Str))
  println(unparser.parse(unparser.value,getTypeDefStr("str4")))
  println(unparser.parse(unparser.value,getTypeDef2Str("str5")))
  println(unparser.parse(unparser.values,"{ \"items\" : [ " + singleStr + " ] }"))
  println(unparser.parse(unparser.literal,"{ \"literal\" : \"some string\" }"))
  
  val originals = Unpickler(result8)
  println(originals)
  
  println(values == originals)
  for ( valu <- values ) {
    println(valu)
  }
  
  println("*********")
  
  for ( orig <- originals) {
    println(orig)
  }
  
  println(values(0) == originals(0))
  println(values(1) == originals(1))
  println(values(2) == originals(2))
  
  println(originals(0) == originals(0))
  println(originals(1) == originals(1))
  println(originals(2) == originals(2))
}